Linux 内核源码外编译 linux模块 |
您所在的位置:网站首页 › linux 驱动模块编译 › Linux 内核源码外编译 linux模块 |
1、先编写一个简单的hello模块,hello.c 源码如下: #ifndef __KERNEL__ # define __KERNEL__ #endif #ifndef MODULE # define MODULE #endif // 下面的是主要的内容 #include #include #include MODULE_LICENSE("GPL"); static int year=2012; int hello_init() { printk(KERN_WARNING "Hello kernel, it's %d!\n",year); return 0; } void hello_exit() { printk("Bye, kernel!\n"); } // 下面两个为关键的模块函数 module_init(hello_init); module_exit(hello_exit);如果上面的代码看起来不太熟悉,那么需要查看以下相关的书籍,比如《Linux设备驱动程序,第三版》,也就是大名鼎鼎的LDD; 2、老式驱动模块编译方法: 直接写出make规则到makefile文件中,引用内核体系的头文件路径,举例如下: # The path of kernel source code INCLUDEDIR = /media/GoldenResources/linux/linux-2.6.30/include # Compiler CC = gcc # Options CFLAGS = -D__KERNEL__ -DMODULE -O -Wall -I$(INCLUDEDIR) # Target OBJS = hello.o all: $(OBJS) $(OBJS): hello.c $(CC) $(CFLAGS) -c $ |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |